package com.monkeysonnet.b2dFluent;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.physics.box2d.joints.RevoluteJoint;
import com.badlogic.gdx.physics.box2d.joints.RevoluteJointDef;

public class RevoluteJointFactory extends JointFactory<RevoluteJointFactory>
{
	private static final RevoluteJointDef _initialDef = new RevoluteJointDef();
	
	private RevoluteJointDef _def;
	
	public RevoluteJointFactory()
	{
		this(false);
	}
	
	RevoluteJointFactory(boolean managed)
	{
		super(managed);
		_def = new RevoluteJointDef();
		setDef(_def);
	}
	
	public RevoluteJointFactory localAnchorA(float x, float y)
	{
		_def.localAnchorA.set(x, y);
		return this;
	}
	
	public RevoluteJointFactory localAnchorB(float x, float y)
	{
		_def.localAnchorB.set(x, y);
		return this;
	}
	
	public RevoluteJointFactory localAnchorA(Vector2 v)
	{
		_def.localAnchorA.set(v);
		return this;
	}
	
	public RevoluteJointFactory localAnchorB(Vector2 v)
	{
		_def.localAnchorB.set(v);
		return this;
	}
	
	public RevoluteJointFactory enableLimit(boolean b)
	{
		_def.enableLimit = b;
		return this;
	}
	
	public RevoluteJointFactory enableMotor(boolean b)
	{
		_def.enableMotor = b;
		return this;
	}
	
	public RevoluteJointFactory lowerAngle(float a)
	{
		_def.lowerAngle = a;
		return this;
	}
	
	public RevoluteJointFactory maxMotorTorque(float t)
	{
		_def.maxMotorTorque = t;
		return this;
	}
	
	public RevoluteJointFactory motorSpeed(float s)
	{
		_def.motorSpeed = s;
		return this;
	}
	
	public RevoluteJointFactory referenceAngle(float a)
	{
		_def.referenceAngle = a;
		return this;
	}
	
	public RevoluteJointFactory upperAngle(float a)
	{
		_def.upperAngle = a;
		return this;
	}
	
	public RevoluteJoint create(World w)
	{
		return (RevoluteJoint)w.createJoint(_def);
	}
	
	void clear()
	{
		super.clear(_initialDef);
		_def.enableLimit = _initialDef.enableLimit;
		_def.enableMotor = _initialDef.enableMotor;
		_def.localAnchorA.set(_initialDef.localAnchorA);
		_def.localAnchorB.set(_initialDef.localAnchorB);
		_def.lowerAngle = _initialDef.lowerAngle;
		_def.maxMotorTorque = _initialDef.maxMotorTorque;
		_def.motorSpeed = _initialDef.motorSpeed;
		_def.referenceAngle = _initialDef.referenceAngle;
		_def.upperAngle = _initialDef.upperAngle;		
	}

	@Override
	public void free()
	{
		B2d.free(this);
	}
}
